package com.hnhy.hnhyscms_ws.controller;

import com.hnhy.hnhyscms_ws.entity.Customers;
import com.hnhy.hnhyscms_ws.service.ICustomersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/customers")
public class CustomersController {
    @Autowired
    private ICustomersService iCustomersService;
    @RequestMapping(value = "/getAllCustomers",method= RequestMethod.GET)
    public List<Customers> getAllCustomers(){ return iCustomersService.getAllCustomers(); }
    @RequestMapping(value = "/getByCustomerNo",method = RequestMethod.POST)
    public Customers getByCustomerNo(@RequestParam String customerNo){ return  iCustomersService.getByCustomerNo(customerNo); }
    @RequestMapping(value = "/deleteCustomers",method = RequestMethod.POST)
    public void deleteCustomers(@RequestParam String customerNo){  iCustomersService.deleteCustomers(customerNo); }
    @RequestMapping(value = "/changeByCustomerNo",method = RequestMethod.POST)
    public void changeBySupplierNo(
            @RequestParam String customerNo,
            @RequestParam String customerName,
            @RequestParam String linkPerson,
            @RequestParam String linkPhone,
            @RequestParam String linkAddr,
            @RequestParam String invoiceInfo,
            @RequestParam String fax,
            @RequestParam String remarks){
        Customers customers=new Customers();
        customers.setCustomerNo(customerNo);
        customers.setCustomerName(customerName);
        customers.setLinkPerson(linkPerson);
        customers.setLinkPhone(linkPhone);
        customers.setLinkAddr(linkAddr);
        customers.setInvoiceInfo(invoiceInfo);
        customers.setFax(fax);
        customers.setRemarks(remarks);
        iCustomersService.changeByCustomerNo(customers);
    }
    @RequestMapping(value = "/addCustomers",method = RequestMethod.POST)
    public void addCustomers(
            @RequestParam String customerName,
            @RequestParam String linkPerson,
            @RequestParam String linkPhone,
            @RequestParam String linkAddr,
            @RequestParam String areaName,
            @RequestParam String invoiceInfo,
            @RequestParam String fax,
            @RequestParam String remarks)
    {
        byte status=1;
        Customers customers=new Customers();
        customers.setCustomerName(customerName);
        customers.setLinkPerson(linkPerson);
        customers.setLinkPhone(linkPhone);
        customers.setLinkAddr(linkAddr);
        customers.setAreaName(areaName);
        customers.setInvoiceInfo(invoiceInfo);
        customers.setFax(fax);
        customers.setRemarks(remarks);
        customers.setStatus(status);
        customers.setCustomerNo("hyC"+"0000"+(iCustomersService.findMaxId().getCid()+1));
        iCustomersService.addCustomers(customers);
        return;
    }
}
